import UserServices from '../../services/account/UserServices'
import { NavigationActions, Storage } from '../../utils'
import { Toast } from 'antd-mobile';

export default {
    namespace: 'user',
    state: {
        loading: false,
        loginSuccess: false
    },
    subscriptions: {
    },
    effects: {
        *login({ payload }, { call, put }) {
            yield put({ type: 'setLoading', payload: true });
            const result = yield call(UserServices.Login, payload);
            yield put({ type: 'setLoading', payload: false });
            const { data } = result;
            if (data.success) {
                Storage.set("userInfo", data.data);
                Toast.info(data.message, 2, null, false);
            }
            else {
                Toast.info(data.message, 2, null, false);
            }
        },
    },
    reducers: {
        setindex(state, { payload }) {
            return { ...state, indexInfo: payload }
        },
        setLoading(state, { payload }) {
            return { ...state, loading: payload }
        },
        setLoginSuccess(state, { payload }) {
            return { ...state, loginSuccess: payload }
        }
    },
}